namespace MergeFileWinForm
{
    public partial class Form1 : Form
    {
        string[] infileName = new string[2];
        public Form1()
        {
            InitializeComponent();
            
        }

        

        private void button1_Click(object sender, EventArgs e)
        {
            infileName[0] = "E:\\Visual Studio Workspace\\c#homework5\\MergeFileWinForm\\bin\\Debug\\net6.0-windows\\Data\\File1.txt";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            infileName[1] = "E:\\Visual Studio Workspace\\c#homework5\\MergeFileWinForm\\bin\\Debug\\net6.0-windows\\Data\\File2.txt";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FileStream[] fileIn = new FileStream[2];
            using(FileStream fileOut = new FileStream("E:\\Visual Studio Workspace\\c#homework5\\MergeFileWinForm\\bin\\Debug\\net6.0-windows\\Data\\merge.txt", FileMode.Create))
            {
                int b;
                for (int i = 0; i < fileIn.Length; i++)
                {
                    try
                    {
                        fileIn[i] = new FileStream(infileName[i], FileMode.Open);
                        while ((b = fileIn[i].ReadByte()) != -1)
                        {
                            fileOut.WriteByte((byte)b);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        fileIn[i].Close();
                    }
                }
                fileOut.Close();   
            }
        }
    }
}